#1.尝试不使用进程池，可否循环创建多个进程并调用
# from multiprocessing import Process
#
#
# def Func(k):
#     print('process:', k)
#
#
# if __name__ == "__main__":
#     for i in range(5):
#         p1 = Process(target=Func, args=(str(i)))
#         p1.start()
#2.使用UDP协议编写一个局域网聊天程序
# server端:
# from socket import *
# from threading import Thread
# sk = socket(AF_INET, SOCK_DGRAM)
# sk.bind(('127.0.0.1', 8080))
# msg, addr = sk.recvfrom(1024)
# def Send():
#     while 1:
#         try:
#             smsg = input('>>>')
#             sk.sendto(smsg.encode('utf-8'), addr)
#         except Exception:
#             break
# def Recv():
#     while 1:
#         msg, addr = sk.recvfrom(1024)
#         print('<<<', msg.decode('utf-8'))
#         if msg.decode('utf-8') == 'bye':
#             sk.sendto('bye'.encode('utf-8'), addr)
#             break
# if __name__ == '__main__':
#     print('<<<', msg.decode('utf-8'))
#     p1 = Thread(target=Send)
#     p2 = Thread(target=Recv)
#     p1.start()
#     p2.start()
#     p2.join()
#     sk.close()

#client端:
# from socket import *
# from threading import Thread
# sk = socket(AF_INET, SOCK_DGRAM)
# ip_port = ('127.0.0.1', 8080)
# def Send():
#     while 1:
#         smsg = input('>>>')
#         sk.sendto(smsg.encode('utf-8'), ip_port)
#         if smsg == 'bye':
#             break
# def Recv():
#     while 1:
#         try:
#             msg, addr = sk.recvfrom(1024)
#             print(msg.decode('utf-8'))
#             if msg.decode('utf-8')=='bye':
#                 break
#         except Exception:
#             continue
# if __name__ == '__main__':
#     p1 = Thread(target=Send)
#     p2 = Thread(target=Recv)
#     p1.start()
#     p2.start()
#     p1.join()
#     p2.join()
#     sk.close()
#3，使用TCP协议编写一个能同时支持多个客户端访问的服务器
# import socketserver
# class Myserver(socketserver.BaseRequestHandler):
#     def handle(self):
#         while 1:
#             print(self.request.recv(1024).decode("utf-8"))
#
# if __name__ == "__main__":
#     socketserver.TCPServer.allow_reuse_address = True
#     server = socketserver.ThreadingTCPServer(("127.0.0.1", 8080),Myserver)
#     server.serve_forever()